<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态组件</title>
    <script src="lib/vue.js"></script>

<body>
    <div id="box">
        <!-- 动态组件 -->
        <keep-alive>
            <component :is="who"></component>
        </keep-alive>

        <footer>
            <ul>
                <li><a @click="who='home'" href="#">首页</a></li>
                <li><a @click="who='list'" href="#">列表页</a></li>
                <li><a @click="who='shopcar'" href="#">购物车页面</a></li>
            </ul>
        </footer>

    </div>

    <script>
        new Vue({
            el: "#box",
            data: {
                who: "home"
            },
            components: {
                "home": {
                    template: `<div>
                        Home
                        <input type="text">
                        </div>`
                },
                "list": {
                    template: `<div>List</div>`
                },
                "shopcar": {
                    template: `<div>Shopcar</div>`
                }

            }
        })
    </script>
</body>

</html>